From: Florian Müllner Date: Fri, 11 Aug 2023 22:03:38 +0000 (+0200) Subject: extensionBase: Use UUID as fallback gettext domain X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~320^2^2~39 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=a6d8e7ab6fe8cb3eaf30feb27434cc3ec725b291;p=gnome-shell.git extensionBase: Use UUID as fallback gettext domain Nowadays we can set up translations automatically, but only when the domain is provided with the metadata. This can be a problem, for example our extension templates use the automatic translation handling that we recommend, but as a result the code will throw an error unless `gettext-domain` is added to the metadata. Binding a text domain is cheap enough to not care about unnecessary or duplicated calls, so add a final fallback to the UUID when no domain was provided as parameter or in the metadata. There is already a precedent with the `gnome-extensions pack` command that falls back to the UUID when no explicit gettext domain was included in the metadata. Part-of: --- diff --git a/js/extensions/sharedInternals.js b/js/extensions/sharedInternals.js index c9cb8e9c8..1e3ac6dba 100644 --- a/js/extensions/sharedInternals.js +++ b/js/extensions/sharedInternals.js @@ -55,10 +55,7 @@ export class ExtensionBase { throw new Error(`${this.constructor.name} did not pass metadata to parent`); this.metadata = metadata; - - const domain = this.metadata['gettext-domain']; - if (domain) - this.initTranslations(domain); + this.initTranslations(); } /** @@ -116,14 +113,12 @@ export class ExtensionBase { /** * Initialize Gettext to load translations from extensionsdir/locale. If * domain is not provided, it will be taken from metadata['gettext-domain'] + * if provided, or use the UUID * * @param {string=} domain - the gettext domain to use */ initTranslations(domain) { - domain ||= this.metadata['gettext-domain']; - - if (!domain) - throw new Error('initTranslations() was called without providing a valid domain'); + domain ||= this.metadata['gettext-domain'] ?? this.uuid; // Expect USER extensions to have a locale/ subfolder, otherwise assume a // SYSTEM extension that has been installed in the same prefix as the shell